Skip to content

refactor!: rename useThemeSwitcher to useColorMode - #3

Merged
maxcwolf merged 3 commits into
mainfrom
refactor/use-color-mode
Nov 8, 2026
Merged

maxcwolf merged 3 commits into
mainfrom
refactor/use-color-mode

Conversation

@maxcwolf

@maxcwolf maxcwolf commented Nov 8, 2026

Copy link
Copy Markdown
Owner

What and why

Theme switching gets the name other libraries use: useColorMode(). The ThemeProvider props follow it. useTheme() stays a separate hook that returns only the theme's tokens, as in MUI (useTheme / useColorScheme) and Chakra (useTheme / useColorMode).

Before After
useThemeSwitcher() → { preference, setPreference, name, names, theme } useColorMode() → { mode, setMode, name, names, theme }
<ThemeProvider preference defaultPreference onPreferenceChange> <ThemeProvider mode defaultMode onModeChange>
ThemePreference, ThemeSwitcher ColorMode, ColorModeState

ESLint now stops components and primitives from importing useColorMode, so only app code can change the mode. I checked that it fires by importing it in Card.tsx. ADR 0005 is amended to match.

Merge order: #1 adds a screen reader transcript of the theme-switching story that still reads (preference: light). Whichever of #1 and this PR merges second needs that transcript rewritten (yarn e2e:update-transcripts).

Checklist

  • yarn check passes.
  • Accessibility: new or changed UI has a role and name, a 44dp target, keyboard access,
    scaling text, and theme colors only; its states have stories (docs/accessibility.md). The only UI change is the switching story's text.
  • Theming: no literal colors or sizes; new color pairings are in contrastRequirements.
  • Public API: if the API snapshot changed, the change is intended and there is a
    changeset (yarn changeset). useThemeSwitcher → useColorMode, with a changeset.
  • Screenshots: if e2e/__screenshots__/ changed, I looked at every changed image. The four foundations-theme--switching images now read "(mode: light)".
  • Dependencies: a new dependency is justified here; the library's allowlist is unchanged
    or an ADR explains why. No new dependencies.
  • Guards: if a guard file changed (ESLint, dependency-cruiser, tsconfig.base, knip,
    lefthook, Jest or Playwright config), the reason and an ADR are linked here. eslint.config.mjs adds a restriction and loosens nothing (ADR 0005).

Verified

  • yarn check passes: 133 UI tests at 100% coverage.
  • yarn e2e:docker: 204 passed, including visual.

useColorMode() returns { mode, setMode, name, names, theme }. The
ThemeProvider props are now mode, defaultMode and onModeChange, and
ThemePreference is ColorMode. useTheme() is unchanged and still returns
only the theme's tokens. ESLint now stops components and primitives
from importing useColorMode, so only app code changes the mode.

BREAKING CHANGE: useThemeSwitcher, setPreference, preference,
defaultPreference, onPreferenceChange and ThemePreference are renamed
to useColorMode, setMode, mode, defaultMode, onModeChange and ColorMode.
@maxcwolf
maxcwolf merged commit 8521f2c into main Nov 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant